<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:variable name="type"><xsl:value-of select="/modules/module/@type"/></xsl:variable>
<xsl:variable name="name"><xsl:value-of select="/modules/module/@name"/></xsl:variable>
<xsl:variable name="mode"><xsl:value-of select="/modules/mode/@id"/></xsl:variable>

<xsl:template match="/modules">
<html>
<head>
</head><body>
<!-- =Show list of modules and available options =========================== -->
<div>
Choose module:
<form method="POST">
<select name="m_oldname"><xsl:for-each select="/modules/list/m">
<option value="{text()}">
<xsl:if test="@sel='yes'"><xsl:attribute name="selected">yes</xsl:attribute></xsl:if>
<xsl:value-of select="text()"/></option>
</xsl:for-each>
</select>
<form method="POST">
<input type="hidden" name="mode" value="n"/>
<input type="submit" value="Create new"/>
</form>
<input type="submit" value="Show"/>
<br/>
<xsl:call-template name='radio'><xsl:with-param name="m" select="'p'" /></xsl:call-template>Properties<br/>
<xsl:call-template name='radio'><xsl:with-param name="m" select="'f'" /></xsl:call-template>Files<br/>
<xsl:call-template name='radio'><xsl:with-param name="m" select="'v'" /></xsl:call-template>Variables and filters<br/>
</form>
</div>
<!-- =Edit module properties================================================ -->
<xsl:if test="$mode='p'">
<div>
Module properties:
<form name="modules" method="POST">
<xsl:call-template name="common"/>
<xsl:for-each select="module/*[name()='title' or name()='description']|module/@name">
<xsl:call-template name="prop"/>
</xsl:for-each>

<xsl:for-each select="module/@enabled|module/@external">
<xsl:value-of select="name()"/>:<input type="checkbox" name="m_{name()}">
<xsl:if test=".='on'"><xsl:attribute name="checked">yes</xsl:attribute></xsl:if></input>
<br/>
</xsl:for-each>

<!-- Type selector -->
Module type:
<select name="m_type" size="1">
<xsl:call-template name='opts'><xsl:with-param name="t" select="'html'" /></xsl:call-template>
<xsl:call-template name='opts'><xsl:with-param name="t" select="'xml'" /></xsl:call-template>
<xsl:call-template name='opts'><xsl:with-param name="t" select="'cgi'" /></xsl:call-template>
<xsl:call-template name='opts'><xsl:with-param name="t" select="'ext'" /></xsl:call-template>
</select>
<br/>
<input type="submit" value="OK"/>
<input type="reset" value="Cancel"/>
</form>
</div>
</xsl:if>
<!-- =Edit module files ==================================================== -->
<xsl:if test="$mode='f'">
Module files: 
<div>
<form method="POST">
<xsl:call-template name="common"/>
<input type="hidden" name="m_files" value="{count(/modules/module/files/file)}"/>
<input type="hidden" name="mode2" value="o"/>
<form method="POST">
<xsl:call-template name="common"/>
<input type="submit" value="+"/>
<input type="hidden" name="m_files" value="{count(/modules/module/files/file)}"/>
<input type="hidden" name="mode2" value="a"/>
</form>
<br/>
<xsl:for-each select="module/files/file">
<input type="text" name="file{position()}" value="{@name}"/>
<form method="POST">
<xsl:call-template name="common"/>
<input type="hidden" name="m_files" value="{count(/modules/module/files/file)}"/>
<input type="hidden" name="mode2" value="d"/>
<input type="hidden" name="delF" value="{position()}"/>
<input type="submit" value="Delete"/>
Delete from disk: <input type="checkbox" name="delL"/>
</form>
</xsl:for-each>
<br/>
<input type="submit" value="OK"/>
</form>
</div>
</xsl:if>
<!-- =Show message====================================================== -->
<p><xsl:value-of select="message/text()"/></p>
</body></html>
</xsl:template>

<xsl:template name="prop">
<xsl:value-of select="name()"/>: <input type='text' name="m_{name()}" value="{.|text()}"/>
<br/>
</xsl:template>

<!-- Display options -->
<xsl:template name="opts">
<xsl:param name="t"/>
<option value="{$t}"><xsl:if test="$type=$t"><xsl:attribute name="selected">yes</xsl:attribute></xsl:if>
	<xsl:choose>
		<xsl:when test="$t='html'">Single HTML Document</xsl:when>
		<xsl:when test="$t='xml'">XML file with XSL-stylesheet</xsl:when>
		<xsl:when test="$t='cgi'">Dynamic script</xsl:when>
		<xsl:when test="$t='ext'">External link</xsl:when>
	</xsl:choose></option>
</xsl:template>

<xsl:template name="radio">
<xsl:param name="m"/>
<input type="radio" name="mode" value="{$m}">
<xsl:if test="$mode=$m"><xsl:attribute name="checked">on</xsl:attribute></xsl:if>
</input>
</xsl:template>

<xsl:template name="common">
<input type="hidden" name="m_oldname" value="{$name}"/>
<input type="hidden" name="mode" value="{$mode}"/>
</xsl:template>

</xsl:stylesheet>
